package com.example.spingioc.controller;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/prop")
public class PropertiesController {
    @Value("${my.key}")
    private String myKey;

    @Value("${my.key2}")
    private Integer myKey2;

    @Value("${my.key3}")
    private Boolean myKey3;

    //1.
    @RequestMapping("/readValue")
    public String readValue(){
        return "从配置文件中读取信息" + myKey;
    }

    //2.
    @PostConstruct //构造这个对象的时候就执行这个方法
    public void readValue2(){
        System.out.println(("从配置文件中读取配置信息：" + myKey));
        System.out.println(("从配置文件中读取配置信息：" + myKey2));
        System.out.println(("从配置文件中读取配置信息：" + myKey3));
    }
}
